function httpReq(url, method, data, cb) {
  var header = {
    'Accept': 'application/json',
    'X-Nideshop-Token': wx.getStorageSync('X-Nideshop-Token'),
    'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
  }
  wx.showLoading({
    title: '加载中',
  })
  var options = data
  wx.request({
    url: url,
    method: method,
    header: header,
    data: options,
    success: function(res) {
      wx.hideLoading();
      if(res.data.code == 10002) {
        console.log("-=-=-=-=-=-")
        wx.navigateTo({
          url: '/pages/login/index',
        })
        return
      } 
      if (res.statusCode != 200) {
        wx.showModal({
          title: '服务器走丢了',
          content: '请稍后重试。。。',
          showCancel: false
        })
      }
      return typeof cb == "function" && cb(res.data)
    },
    fail: function() {
      wx.hideLoading();
      wx.showModal({
        title: '服务器走丢了',
        content: '请稍后重试。。。',
        showCancel: false
      })
      return typeof cb == "function" && cb(false)
    }
  })
}

module.exports = {
  httpReq: httpReq,
}